package com.zlt.controller.seeker;

import com.alibaba.fastjson.JSON;
import com.zlt.controller.BaseController;
import com.zlt.service.ChatMessageService;
import com.zlt.service.UserService;
import com.zlt.service.impl.ChatMessageServiceImpl;
import com.zlt.service.impl.UserServiceImpl;
import com.zlt.util.JWTUtil;
import com.zlt.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/seeker/chat_message/*")
public class ChatMessageController extends BaseController {

    private ChatMessageService chatMessageService = new ChatMessageServiceImpl();
    private UserService userService = new UserServiceImpl();
//    private InterviewService interviewService = new InterviewServiceImpl();

    @Override
    protected void defaultMethod(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    //获取当前用户的会话列表
    protected Result showUserChatList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return Result.ok(userService.getRoleByUsername(JWTUtil.getUsername(request.getHeader("token"))) + "", JSON.toJSON(chatMessageService.showUserChatList(request.getHeader("token"))));
    }

    protected Result showChatListByPhone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return Result.ok("", JSON.toJSON(chatMessageService.showChatsByPhone(request.getHeader("token"), request.getParameter("phone"))));
    }
//
//    //查看面试信息
//    protected Result showInterviewInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//
//        String token = request.getHeader("token");
//        try {
//            return Result.ok("查询成功",JSON.toJSON(interviewService.showInfo(token)));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.error(e.getMessage());
//        }
//    }

//    //接受或者拒绝
//    protected Result aor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String token = request.getHeader("token");
//        String state = request.getParameter("state");
//        try {
//            boolean suc = interviewService.AcceptOrReject(token,state);
//            return suc==true ? Result.ok("操作成功"):Result.error("操作失败");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Result.ok(e.getMessage());
//        }
//    }
}
